#include <iostream>
using namespace std;

// CPU基类
class CPU
{
public:
  virtual void caculate() = 0;
};

// 显卡基类
class GPU
{
public:
  virtual void display() = 0;
};

// 内存条类
class Memory
{
public:
  virtual void storage() = 0;
};

// 电脑类
class Computer
{
public:
  Computer(CPU *cpu, GPU *gpu, Memory *memory)
  {
    m_cpu = cpu;
    m_gpu = gpu;
    m_memory = memory;
  }

  virtual void doWork()
  {
    m_cpu->caculate();
    m_gpu->display();
    m_memory->storage();
  };

  // 提供析构释放3个电脑零件
  ~Computer() {
    if (m_cpu != NULL) {
      delete m_cpu;
      m_cpu = NULL;
    }

    if (m_gpu != NULL) {
      delete m_gpu;
      m_gpu = NULL;
    }

    if (m_memory != NULL) {
      delete m_memory;
      m_memory = NULL;
    }
  }

private:
  CPU *m_cpu;
  GPU *m_gpu;
  Memory *m_memory;
};

// 具体零件厂商
class IntelCPU : public CPU
{
public:
  virtual void caculate()
  {
    cout << "Intel CPU开始计算" << endl;
  }
};

class IntelGPU : public GPU
{
public:
  virtual void display()
  {
    cout << "Intel GPU开始显示" << endl;
  }
};

class IntelMemory : public Memory
{
public:
  virtual void storage()
  {
    cout << "Intel Memory开始存储" << endl;
  }
};

class LenovoCPU : public CPU
{
public:
  virtual void caculate()
  {
    cout << "Lenovo CPU开始计算" << endl;
  }
};

class LenovoGPU : public GPU
{
public:
  virtual void display()
  {
    cout << "Lenovo GPU开始显示" << endl;
  }
};

class LenovoMemory : public Memory
{
public:
  virtual void storage()
  {
    cout << "Lenovo Memory开始存储" << endl;
  }
};

void test01()
{
  // 第一台电脑
  CPU *intelCpu = new IntelCPU;
  GPU *intelGpu = new IntelGPU;
  Memory *intelMem = new IntelMemory;

  Computer *intelCom = new Computer(intelCpu, intelGpu, intelMem);
  intelCom->doWork();
  delete intelCom;
}

int main(int argc, char const *argv[])
{
  test01();

  return 0;
}